﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace MetaSharp.Transformation.Tests.Patterns
{
	public class ZeroOrMoreTests
	{
        [Fact]
		public async Task NoMatchesSucceds()
		{
            var p = Pattern.ZeroOrMore(Pattern.Any());
            var m = await Pattern.Match(p, "");
            Assert.True(m.Matched);
		}

        [Fact]
		public async Task SingleMatchSucceeds()
		{
            var p = Pattern.ZeroOrMore(Pattern.Any());
            var m = await Pattern.Match(p, "a");
            Assert.Equal(new object[] { 'a' }, m.Value);
		}

        [Fact]
		public async Task MultipleMatchesSucceed()
		{
            var p = Pattern.ZeroOrMore(Pattern.Any());
            var m = await Pattern.Match(p, "abc");
            Assert.Equal(new object[] { 'a', 'b', 'c' }, m.Value);
		}

        [Fact]
		public async Task MatchesAndReadsToCorrectPosition()
		{
            var p = Pattern.And(
                Pattern.ZeroOrMore(Pattern.Value('a')), 
                Pattern.ZeroOrMore(Pattern.Value('b')));
            var m = await Pattern.Match(p, "aabb");
            Assert.Equal(new object[] {
                new object[] { 'a', 'a' },
                new object[] { 'b', 'b' }
            }, 
            m.Value);
		}
	}
}
